package com.ibm.ems.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.ems.dao.FeedbackDAO;
import com.ibm.ems.dto.EventBean;
import com.ibm.ems.util.ConnectionUtil;

/**
 * Servlet implementation class FeedbackServlet
 */
public class FeedbackServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FeedbackServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Connection conn = ConnectionUtil.getConnection();
		FeedbackDAO feedbackDAO = new FeedbackDAO(conn);
		List<EventBean> list = feedbackDAO.getListOfEventsForFeedback();
		
		ConnectionUtil.closeConnection(conn);
		if(list.isEmpty())
		{
			PrintWriter out = response.getWriter();
			out.println("<h3>No more feeback is required</h3>");
			out.println("<a href=\"/EMS1/participant/Homepage.jsp\">Home page</a>");
		}
		else
		{
		request.setAttribute("eventList", list);
		request.getRequestDispatcher("/participant/GetEventsForFeedback.jsp").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
